#include <stdint.h>
#include "lgt8f690a.h"

// default prescalar = MRC/4
// default system clock = 16MHz/4 = 4MHz
#define _XTAL_FREQ 4000000

void sendcmd(uint8_t ca, uint8_t dt);
void sendcmd1(uint8_t ca, uint8_t dt);
void sendcmd2(uint8_t ca, uint8_t dt);
void sendcmd3(uint8_t ca, uint8_t dt);
void sendcdd(uint8_t cmd, uint8_t data1, uint8_t data2);

#define SCL1_BITMSK 0x01
#define SDA1_BITMSK 0x02
#define SCL2_BITMSK 0x04
#define SDA2_BITMSK 0x08
#define SCL3_BITMSK 0x10
#define SDA3_BITMSK 0x20
#define SCL4_BITMSK 0x08
#define SDA4_BITMSK 0x10
#define SYNC_RX_BM	0x20
#define SYNC_TX_BM	0x40
#define SWKY_BITMSK 0x40

#define scl1_dir_out(a) (a&=(~(SCL1_BITMSK)))

#define sda1_dir_out(a) (a&=(~(SDA1_BITMSK)))
#define sda1_dir_in(a) (a|=(SDA1_BITMSK))

#define scl2_dir_out(a) (a&=(~(SCL2_BITMSK)))

#define sda2_dir_out(a) (a&=(~(SDA2_BITMSK)))
#define sda2_dir_in(a) (a|=(SDA2_BITMSK))

#define scl3_dir_out(a) (a&=(~(SCL3_BITMSK)))

#define sda3_dir_out(a) (a&=(~(SDA3_BITMSK)))
#define sda3_dir_in(a) (a|=(SDA3_BITMSK))

#define scl4_dir_out(a) (a&=(~(SCL4_BITMSK)))

#define sda4_dir_out(a) (a&=(~(SDA4_BITMSK)))
#define sda4_dir_in(a) (a|=(SDA4_BITMSK))

#define syrx_dir_in(a) (a|=(SYNC_RX_BM))
#define syrx_pull(a) (a|=(SYNC_RX_BM))

#define sytx_dir_out(a) (a&=(~(SYNC_TX_BM)))

#define swky_dir_in(a) (a|=(SWKY_BITMSK))
#define swky_pull(a) (a|=(SWKY_BITMSK))

#define set_dir_pa(a) (TRISA=a)
#define set_dir_pb(a) (TRISB=a)
#define set_pullup_pa(a) (WPUA=a)
#define set_pullup_pb(a) (WPUB=a)

void wack(void);
void sendbyte(uint8_t dat);
void showall(void);